﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1.Snake
{
    public partial class Snake : Form
    {
        private Palette palette;
        public Snake()
        {
            InitializeComponent();
        }

        private void Snake_Load(object sender, EventArgs e)
        {
            int width, height, size;
            width = height = 20;
            size = 15;
            this.pictureBox1.Width = width * size;
            this.pictureBox1.Height = height * size;
            this.Width = pictureBox1.Width +30;
            this.Height = pictureBox1.Height +30;
            palette = new Palette(width, height, size, this.pictureBox1.BackColor, Graphics.FromHwnd(this.pictureBox1.Handle), 2);
            palette.Start();
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            if (palette != null)
            {
                palette.PaintPalette(e.Graphics);
            }
        }

        private void Snake_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up && palette.direction != Deriction.Down)
            {
                palette.direction = Deriction.Up;
                return;
            }
            if (e.KeyCode == Keys.Down && palette.direction != Deriction.Up)
            {
                palette.direction = Deriction.Down;
                return;
            }
            if (e.KeyCode == Keys.Left && palette.direction != Deriction.Right)
            {
                palette.direction = Deriction.Left;
                return;
            }
            if (e.KeyCode == Keys.Right && palette.direction != Deriction.Left)
            {
                palette.direction = Deriction.Right;
                return;
            }
        }


    }
}
